﻿using SiliconSelect.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SiliconSelect.Views
{
    /// <summary>
    /// ResultSummary.xaml 的交互逻辑
    /// </summary>
    public partial class ResultSummaryView : UserControl
    {
        ResultSummaryViewModel viewModel = new ResultSummaryViewModel();
        public ResultSummaryView()
        {
            InitializeComponent();
            this.DataContext = viewModel;
        }
        /// <summary>
        /// 文本框内容发生改变的时候,去获取是否有值.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            string textVal = (sender as TextBox)!.Text;
            //  检测里面内容发生变化的时候去更新要显示的数据内容
            viewModel.SearchRes.Clear();
            foreach (var item in viewModel.CrystalNames)
            {
                if(!string.IsNullOrEmpty(textVal) && item.Contains(textVal,StringComparison.OrdinalIgnoreCase))
                {
                    viewModel.SearchRes.Add(item);
                }
            }
            if(viewModel.SearchRes.Count > 0)
            {
                viewModel.IsShowSearchList = "Visible";
                viewModel.SelectedIndex = 0;
                viewModel.SelectedItem = viewModel.SearchRes[0];
            }
            else
            {
                viewModel.IsShowSearchList= "Collapsed";
            }
           
        }

        /// <summary>
        /// 双击了选中的晶棒编号
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ListBoxItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            viewModel.CrystalNameInput = viewModel.SearchRes[viewModel.SelectedIndex];
            viewModel.IsShowSearchList = "Collapsed";
        }
    }
}
